Skip to content

[Streams] Handle deleted streams gracefully in feature identification task#254674

Closed
klacabane wants to merge 1 commit intoelastic:mainfrom
klacabane:ralph/issue-531
Closed

[Streams] Handle deleted streams gracefully in feature identification task#254674
klacabane wants to merge 1 commit intoelastic:mainfrom
klacabane:ralph/issue-531

Conversation

@klacabane
Copy link
Copy Markdown
Contributor

Summary

Fix for a race condition where the feature identification background task fails with ERROR when the target stream is deleted between task scheduling and execution.

  • Catches DefinitionNotFoundError when calling getStream() in the task
  • Logs at INFO level instead of ERROR when stream is deleted
  • Returns a successful task deletion result (same as canceled/aborted tasks)

Test plan

  • Added unit tests for the feature identification task to verify:
    • DefinitionNotFoundError is handled gracefully (INFO log, no error)
    • Other errors still fail the task properly (ERROR log)

Closes #254664

Made with Cursor

… task

Fix for a race condition where the feature identification background task
fails with ERROR when the target stream is deleted between task scheduling
and execution. Now catches DefinitionNotFoundError and logs at INFO level
instead of ERROR, returning a successful task deletion result.

Closes elastic#254664

Co-authored-by: Cursor <cursoragent@cursor.com>
@klacabane klacabane added backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes v9.2.0 Feature:Streams This is the label for the Streams Project Team:streams-program Team Label for Streams program labels Feb 24, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!
  • Click to trigger kibana-deploy-cloud-from-pr for this PR!
  • Click to trigger kibana-entity-store-performance-from-pr for this PR!
  • Click to trigger kibana-storybooks-from-pr for this PR!

@klacabane
Copy link
Copy Markdown
Contributor Author

Self-review

Code changes review

features_identification.ts

  • ✅ Import of isDefinitionNotFoundError is correctly added
  • ✅ The error check is positioned at the start of the catch block, before other error handling logic
  • ✅ Uses logger.info() instead of logger.error() as specified in the issue
  • ✅ Returns getDeleteTaskRunResult() which is consistent with the existing canceled/aborted handling pattern
  • ✅ Does not call taskClient.fail() for this case, avoiding the ERROR log mentioned in the issue

features_identification.test.ts

  • ✅ Tests both the positive case (DefinitionNotFoundError handled gracefully) and negative case (other errors still fail properly)
  • ✅ Verifies the correct log level is used (info vs error)
  • ✅ Verifies taskClient.fail() is not called for deleted streams
  • ✅ Mock setup properly simulates the task runner context including the cancellable task wrapper

Potential concerns

  1. Edge case: If getStream() fails with DefinitionNotFoundError after other operations have started (e.g., getSampleDocuments returns but identifyFeatures throws), those partial operations would be abandoned. However, this is acceptable behavior since the stream no longer exists.

  2. Other task types: The same pattern might be applicable to other task definitions (system_identification.ts, onboarding.ts) if they also call getStream(). This could be addressed in a follow-up PR if needed.

Conclusion

The implementation correctly addresses the issue by gracefully handling the race condition where a stream is deleted between task scheduling and execution. The fix follows existing patterns in the codebase and includes appropriate test coverage.

Self-review by Cursor

@klacabane
Copy link
Copy Markdown
Contributor Author

Closing in favor of #254683

@klacabane klacabane closed this Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:Streams This is the label for the Streams Project release_note:skip Skip the PR/issue when compiling release notes Team:streams-program Team Label for Streams program v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Streams] Feature identification task should handle deleted streams gracefully

2 participants